package redis;

import java.util.Timer;
import java.util.TimerTask;
import java.util.concurrent.Executors;
import java.util.concurrent.ScheduledExecutorService;
import java.util.concurrent.TimeUnit;

/**
 * @Author: admin
 * @Description:
 * @Date: 2018/12/11 14:17
 */

public class Timers {
    private Timer timer=null;
    ScheduledExecutorService scheduledThreadPool = Executors.newScheduledThreadPool(5);
    public Timers()
    {
        timer=new Timer();
    }
    public void execTask(){
        timer.schedule(new TimerTask() {
            @Override
            public void run() {
                System.out.println("hello");
                this.cancel();
            }
        },500);
    }

    public void execPoolTask(Integer a){

        scheduledThreadPool.schedule(new Runnable() {
            @Override
            public void run() {
                System.out.println(Thread.currentThread().getId()+  " scheduledThreadPool "+a);
            }
        },3, TimeUnit.SECONDS);
    }
    public static void main(String[] args) {
        Timers timers=new Timers();
        //timers.execTask();
        timers.execPoolTask(1);
        timers.execPoolTask(2);
        timers.execPoolTask(3);
        timers.execPoolTask(4);
        timers.execPoolTask(5);
        timers.execPoolTask(6);
        System.out.println("exit"+Thread.currentThread().getId());
    }
}
